package com.niit.service.impl;

import java.util.List;

import com.niit.bean.Note;
import com.niit.bean.NoteRepo;
import com.niit.bean.User;
import com.niit.dao.NoteDao;
import com.niit.dao.impl.NoteDaoImpl;
import com.niit.service.NoteService;
import com.niit.utils.Page;

public class NoteServiceImpl implements NoteService {
	
	private NoteDao dao = new NoteDaoImpl();
	@Override
	public int add(Note t) {
		return dao.add(t);
	}

	@Override
	public int delete(Note t) {
		return dao.delete(t);
	}

	@Override
	public int update(Note t) {
		return dao.update(t);
	}

	@Override
	public Page<Note> findNotes(User user, String repoId, String pagenum,
			String url) {
		int total = dao.findTotal(user,repoId);//查出总记录数
		Page<Note> page = null;
		if(pagenum == null){
			page = new Page<Note>(total,1);
		}else{
			page = new Page<Note>(total, Integer.parseInt(pagenum));
		}
		List<Note> list = dao.findNotes(user, repoId, page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}

	@Override
	public Page<Note> getPage(String pagenum, String url) {
		return null;
	}

	@Override
	public Note findNoteById(String id) {
		return dao.findNoteById(id);
	}

	@Override
	public int calID4New() {
		return dao.getSeqNextVal();
	}

	@Override
	public boolean isNoteIn(User user, NoteRepo repo) {
		int a = dao.findTotal(user, repo.getRepoId());
		return a>0?true:false;
	}

	@Override
	public int findTotal() {
		return dao.findTotal();
	}
}
